var flag = false;
var FlowProjectModule = function () {

	$('#btn_reset').click(function(){
		$('#urls').val('');
	});
	
	editable = function () {
        return {
            init: function () {
                 oTable = $('#modelEditable').dataTable({
                    "lengthMenu": [
                        [10, 15, 20, 50],
                        [10, 15, 20, 50]
                    ],
                    "autoWidth":false,
                    "displayLength": 10,
                    "scrollX": true,
                    "language": {
                        "lengthMenu": "每页 _MENU_ 条记录",
                        "paginate": {
                            "previous": "上一页",
                            "next": "下一页"
                        },
                        "info" : "从 _START_ 到  _END_ 条，总记录为 _TOTAL_ 条",    
                        "infoEmpty" : "记录数为0",
                    },
                    "columnDefs": [
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [0]
						},
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [1]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [2]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [3]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [4]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [5]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "-",
						    "targets": [6]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "-",
						    "targets": [7]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "-",
						    "targets": [8]
						}
                    ],
                    "columns": [
                       { "data": "code" },
                       { "data": "name" },
                       { "data": "type" },
                       { "data": "enterpriseName" },
                       { "data": "amount" },
                       { "data": "createTime" },
                       { "data": "approveName" },
                       { "data": "stateType" },
                       { "data": "operter" }
                   ],
                   "filter" : false,
                   "processing": false,
                   "serverSide": true,
                   "ajaxSource": ctx + "/project/queryProject",
                   "serverMethod": "post",
                   "fnRowCallback" : function(nRow, aData, displayIndex) {
                	   nRow.children[0].id = aData.id;
                	   nRow.children[0].name = aData.name;
                	   var type = aData.type;
                	   if (type == '1') {
                		   $('td:eq(2)', nRow).html('债券');
                	   }else if(type == '2'){
                		   $('td:eq(2)', nRow).html('股权');
                	   }
                	   var enterpriseName = aData.enterpriseName;
                	   var smallEName = enterpriseName.substr(0, 20);
                	   if(enterpriseName.length >20){
                		   $('td:eq(3)', nRow).html("<p title="+clearBr(enterpriseName)+">"+smallEName+'......</p>');
                	   }
                	   var name = aData.name;
                	   var smallName = name.substr(0, 20);
                	   if(name.length >20){
                		   $('td:eq(1)', nRow).html("<p title="+clearBr(name)+">"+smallName+'......</p>');
                	   }
                	   $('td:eq(4)', nRow).html(formatCurrency(aData.amount));
                	   var createTime = aData.createTime;
                	   $('td:eq(5)', nRow).html(createTime.substring(0,10));
                	   var operater = '<a class="detail fa fa-bars fa-lg " title="查看" href="javascript:;"></a>&nbsp;&nbsp;&nbsp;<a class="modify fa fa-pencil fa-lg" title="修改" href="javascript:;"></a>&nbsp;&nbsp;&nbsp;';
                	   if(aData.operter!= null){
                		   operater = operater + aData.operter;
                	   }
                	   $('td:eq(8)', nRow).html(operater);
                       return nRow;
                   },
                   "fnServerData" : function(ajaxSource, dataSet, fnCallback) {
	                   var json = "";
	                   var s;
	                   for (var i = 0; i < dataSet.length; i++) {
	                       s = dataSet[i];
	                   	   if (s.name == 'sEcho') {
	                   		   json = json + '"echo":' + s.value;
		                   } else if (s.name == 'iDisplayStart') {
		                	   json = json + ',"start":' + s.value;
		                   } else if (s.name == 'iDisplayLength') {
		                	   json = json + ',"pageSize":' + s.value;
		                   }
	                   }
            	       var form = $("form#queryForm").serializeJSON();
                   	   var js = form.replace('}', ',');
                   	   json = js + json + "}";
                       $.ajax({
                       	   "contentType":"application/json; charset=UTF-8",
                           "dataType" : 'json',
                           "type" : "POST",
                           "url" : ctx + "/project/queryProject",
                           "data" : json,
                           "success" : fnCallback
                       });
                   },
                });
                //查看项目
                $('#modelEditable').on("click", "a.detail", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    window.location.href = ctx +"/project/detail/"+id;
                    return;
                }));
                //修改项目
                $('#modelEditable').on("click", "a.modify", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    window.location.href = ctx +"/project/edit/"+id;
                    return;
                }));
                //投资经理提交项目审批
                $('#modelEditable').on("click", "a.upload", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var eventId = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $.teninedialog({
                	    title:'系统提示',
                	    content:'确认提交['+name+']进行审批吗?',
                	    showCloseButton:false,
                	    otherButtons:["确定","取消"],
                	    otherButtonStyles:['btn-primary','btn-white'],
                	    bootstrapModalOption:{keyboard: true},
                	    clickButton:function(sender,modal,index){
                	    	if(index == 0){
                	    		 //提交审批
    	            	   		var json = "{\"eventId\":\""+eventId+"\",\"step\":"+1+",\"state\":"+2+",\"isSugesst\":"+false+",\"flag\":"+true+"}";
    	            	   		FlowUnitiveHandleRequest(json);
    	            	   		//创建项目的尽调小组
    	            	   		var json1 = "{\"projectId\":\""+eventId+"\"}";
    	            	   		createSurveyGroup(json1);
                	    	}
	                	   	$(this).closeDialog(modal); 
                	    }
                	});
                }));
                //投资部主管审核 
                $('#modelEditable').on("click", "a.approve", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $("#approve_project_err_span").css('display','none');
                    $("#projectName").html(name);
                    $("#approve_project_eventId").val(id);
                    $("#approve_project_suggestion").val("");
                    $("#approveProject").click();
                }));
                //查看尽调小组 
                $('#modelEditable').on("click", "a.group", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    $("#group_project_eventId").val(id);
                    $("#group").click();
                    $("#employeeName").html('');
                    $("#employeeNo").html('');
                    $("#employeeId").val('');
                    $("#tags").val("");
                    var json = "{\"id\":\""+id+"\"}";
                    //获取项目尽调小组审批团队
                    getSurveyGroup(json);
                    oTable2.fnClearTable();
                }));
                //重启立项 
                $('#modelEditable').on("click", "a.restart", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var eventId = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $.teninedialog({
                	    title:'系统提示',
                	    content:'确认重启['+name+']这个项目吗?',
                	    showCloseButton:false,
                	    otherButtons:["确定","取消"],
                	    otherButtonStyles:['btn-primary','btn-white'],
                	    bootstrapModalOption:{keyboard: true},
                	    clickButton:function(sender,modal,index){
                	    	if(index == 0){
                	    		 //重启立项提交
    	            	   		var json = "{\"eventId\":\""+eventId+"\",\"step\":"+2+",\"state\":"+100+",\"isSugesst\":"+false+",\"flag\":"+true+"}";
    	            	   		FlowUnitiveHandleRequest(json);
                	    	}
	                	   	$(this).closeDialog(modal); 
                	    }
                	});
                }));
                //立项风控审核 
                $('#modelEditable').on("click", "a.windControl", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $("#windControl_err_span").css('display','none');
                    $("#windprojectName").html(name);
                    $("#windControl_project_eventId").val(id);
                    $("#windControl_project_suggestion").val("");
                    $("#windControl").click();
                }));
                //确认尽调完成
                $('#modelEditable').on("click", "a.comfirm", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $("#carefulComplete_err_span").css('display','none');
                    $("#carefulCompleteName").html(name);
                    $("#carefulComplete_project_eventId").val(id);
                    $("#carefulComplete_project_suggestion").val("");
                    $("#carefulComplete").click();
                }));
                //初审委员会个人表决
                $('#modelEditable').on("click", "a.vote", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $("#vote_err_span").css('display','none');
                    $("#voteName").html(name);
                    $("#vote_project_eventId").val(id);
                    $("#vote_project_suggestion").val("");
                    $("#vote").click();
                }));
                //初审委员会负责人提交初审结果
                $('#modelEditable').on("click", "a.firstTrial", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    var table = document.getElementById("detail_options_table");
                    var tableLength = table.rows.length;
                    for(var int = 1;int < tableLength;int++) {
                       table.deleteRow(int);
                    }	
                    var stepName = '初审委员会成员审批';
                    json = "{\"eventId\":\""+id+"\",\"stepName\":\""+stepName+"\"}";
                    $.ajax({
                    	type:"post",
                        contentType:"application/json; charset=UTF-8",
                        url: ctx + "/projectFlow/queryVoteDetail",
                        data:json,
                        dataType:"json",
                        success: function(msg){
                       	$("#btn_detail_Modal").click();
                        	var data = msg.data;
                        	var code = msg.code;
                        	if(code == 1){
                        		var options = data;
                        		for(var i=options.length-1;i>=0;i--){
                        			var isMult = "否";
                         			if(options[i].result == 1){
                         				isMult = "是";
                         			}
                        			var tableStr= "<tr role=\"row\" class=\"odd\"><td style=\"font-size:13px;\"> <center>"+options[i].employeeName+"</center></td>"+
                        			"<td style=\"font-size:13px;\">"+options[i].createTime+"</td>"+
                        			"<td style=\"font-size:13px;\"><center>"+isMult+"</center></td>"+
                        			"<td style=\"font-size:13px;\"><center>"+options[i].suggestion+"</center></td>"+
                        			"</tr>";
                        			$("#detail_options_table tr:eq(0)").after(tableStr);
                        		}
                        	}else{
                        		bootbox.alert("服务器出错了,查看复审结果失败了!");
                        	}
                        },
                        error: function (msg) {
                        	bootbox.alert("服务器出错了,查看复审结果失败了!");
                        }
                    });
                    $("#firstTrial_err_span").css('display','none');
                    $("#firstTrialName").html(name);
                    $("#firstTrial_project_eventId").val(id);
                    $("#firstTrial_project_suggestion").val("");
                    $("#firstTrial").click();
                }));
                //初审委员会负责人提交复审
                $('#modelEditable').on("click", "a.recheck", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var eventId = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $.teninedialog({
                	    title:'系统提示',
                	    content:'确认提交['+name+']项目至复审吗?',
                	    showCloseButton:false,
                	    otherButtons:["确定","取消"],
                	    otherButtonStyles:['btn-primary','btn-white'],
                	    bootstrapModalOption:{keyboard: true},
                	    clickButton:function(sender,modal,index){
                	   	 //提交审批
                	   	 if(index == 0){
                	   		var json = "{\"eventId\":\""+eventId+"\",\"step\":"+6+",\"state\":"+7+",\"isSugesst\":"+false+",\"flag\":"+true+"}";
                	   		FlowUnitiveHandleRequest(json);
                	   	 }
                	   	 $(this).closeDialog(modal); 
                	    }
                	});
                }));
                //复审委员会个人决议
                $('#modelEditable').on("click", "a.decision", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $("#decision_err_span").css('display','none');
                    $("#decisionName").html(name);
                    $("#decision_project_eventId").val(id);
                    $("#decision_project_suggestion").val("");
                    $("#decision").click();
                }));
                //复审委员会负责人提交复审结果
                $('#modelEditable').on("click", "a.reexamine", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    var table = document.getElementById("reexamine_options_table");
                    var tableLength = table.rows.length;
                    for(var int = 1;int < tableLength;int++) {
                       table.deleteRow(int);
                    }	
                    var stepName = '决策委员会成员审批';
                    json = "{\"eventId\":\""+id+"\",\"stepName\":\""+stepName+"\"}";
                    $.ajax({
                    	type:"post",
                        contentType:"application/json; charset=UTF-8",
                        url: ctx + "/projectFlow/queryVoteDetail",
                        data:json,
                        dataType:"json",
                        success: function(msg){
                       	$("#btn_detail_Modal").click();
                        	var data = msg.data;
                        	var code = msg.code;
                        	if(code == 1){
                        		var options = data;
                        		for(var i=options.length-1;i>=0;i--){
                        			var isMult = "否";
                         			if(options[i].result == 1){
                         				isMult = "是";
                         			}
                        			var tableStr= "<tr role=\"row\" class=\"odd\"><td style=\"font-size:13px;\"> <center>"+options[i].employeeName+"</center></td>"+
                        			"<td style=\"font-size:13px;\">"+options[i].createTime+"</td>"+
                        			"<td style=\"font-size:13px;\"><center>"+isMult+"</center></td>"+
                        			"<td style=\"font-size:13px;\"><center>"+options[i].suggestion+"</center></td>"+
                        			"</tr>";
                        			$("#reexamine_options_table tr:eq(0)").after(tableStr);
                        		}
                        	}else{
                        		bootbox.alert("服务器出错了,查看复审结果失败了!");
                        	}
                        },
                        error: function (msg) {
                        	bootbox.alert("服务器出错了,查看复审结果失败了!");
                        }
                    });
                    $("#reexamine_err_span").css('display','none');
                    $("#reexamineName").html(name);
                    $("#reexamine_project_eventId").val(id);
                    $("#reexamine_project_suggestion").val("");
                    $("#reexamine").click();
                }));
                //复审委员会负责人提交终审
                $('#modelEditable').on("click", "a.submitFinal", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var eventId = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $.teninedialog({
                	    title:'系统提示',
                	    content:'确认提交['+name+']项目至终审吗?',
                	    showCloseButton:false,
                	    otherButtons:["确定","取消"],
                	    otherButtonStyles:['btn-primary','btn-white'],
                	    bootstrapModalOption:{keyboard: true},
                	    clickButton:function(sender,modal,index){
                	   	 //提交审批
                	   	 if(index == 0){
                	   		var json = "{\"eventId\":\""+eventId+"\",\"step\":"+8+",\"state\":"+9+",\"isSugesst\":"+false+",\"flag\":"+true+"}";
                	   		FlowUnitiveHandleRequest(json);
                	   	 }
                	   	 $(this).closeDialog(modal); 
                	    }
                	});
                }));
                //终审负责人终审审批
                $('#modelEditable').on("click", "a.lastInstance", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $("#lastInstance_err_span").css('display','none');
                    $("#lastInstanceName").html(name);
                    $("#lastInstance_project_eventId").val(id);
                    $("#lastInstance_project_suggestion").val("");
                    $("#lastInstance").click();
                }));
                //上传尽调文件
                $('#modelEditable').on("click", "a.report", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var name = nRow.children[0].name;
                    $("#report_project_eventId").val(id);
                    $("#report").click();
                    oTable1.fnClearTable();
                }));
                
                
                $('#btn_query').click(function(){
                	oTable.fnClearTable();
                });
            }

        };
    }();
    return {
        init: function () {
        	editable.init();
        	
        }
    };
}();

var ProjectReport = function() {
	var editable1 = function() {

		return {
			init : function() {
				oTable1 = $('#modelEditable_report').dataTable(
								{
									"autoWidth" : false,
									"lengthMenu" : [ [ 10, 15, 20, 50, -1 ],
											[ 10, 15, 20, 50, "All" ] ],
									"displayLength" : -1,
									"language" : {
										"lengthMenu" : "每页 _MENU_ 条记录",
										"paginate" : {
											"previous" : "上一页",
											"next" : "下一页"
										},
										"info" : "",// "从 _START_ 到 _END_ 条，总记录为
													// _TOTAL_ 条",
										"infoEmpty" : "",// 记录数为0",
										"sZeroRecords" : "找不到相关数据"
									},
									"bPaginate" : false, // 是否显示分页
									"bLengthChange" : false, // 每页显示的记录数
									"columnDefs" : [ {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 0 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 1 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 2 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 3 ]
									} ],
									"columns" : [ {
										"data" : "contractName"
									}, {
										"data" : "employeeName"
									}, {
										"data" : "createTime"
									}, {
										"data" : "operater"
									}],
									"filter" : false,
									"processing" : false,
									"serverSide" : true,
									"ajaxSource" : ctx
											+ "/project/projectReport",
									"serverMethod" : "post",
									"fnRowCallback" : function(nRow, aData,displayIndex) {
										nRow.children[0].id = aData.id;
										nRow.children[0].name = aData.contractName;
										var roleType = aData.roleType
										var roleName ="";
										$('td:eq(3)', nRow).html('<a class="delete fa fa-trash-o fa-lg " title="移除" href="javascript:;"></a>&nbsp;&nbsp;&nbsp;<a class="modify fa fa-cog fa-lg " title="重命名" href="javascript:;"></a>');
										return nRow;
									},
									"fnServerData" : function(ajaxSource,dataSet, fnCallback) {
										var start;
										var pageSize;
										for (var i = 0; i < dataSet.length; i++) {
											s = dataSet[i];
											if (s.name == 'iDisplayStart') {
												start = s.value;
											} else if (s.name == 'iDisplayLength') {
												pageSize = s.value;
											}
										}
										var id = $("#projectId").val();
										$.ajax({
													"contentType" : "application/json; charset=UTF-8",
													"dataType" : 'json',
													"type" : "POST",
													"url" : ajaxSource,
													"data" : '{"projectId":"'
															+ $("#report_project_eventId").val()
															+ '","start":'
															+ start
															+ ',"type":'
															+ 2
															+ ',"pageSize":'
															+ pageSize + "}",
													"success" : fnCallback
												});
									},
								});
							 //移除尽调文件
			                $('#modelEditable_report').on("click", "a.delete", (function (e) {
			                    e.preventDefault();
			                    var nRow = $(this).parents('tr')[0];
			                    var id = nRow.children[0].id;
			                    var name = nRow.children[0].name;
			                    $.teninedialog({
			                	    title:'系统提示',
			                	    content:'确认移除['+name+']尽调文件吗?',
			                	    showCloseButton:false,
			                	    otherButtons:["确定","取消"],
			                	    otherButtonStyles:['btn-primary','btn-white'],
			                	    bootstrapModalOption:{keyboard: true},
			                	    clickButton:function(sender,modal,index){
			                	   	 //移除文件
			                	   	 if(index == 0){
			                	   		//var json = "{\"id\":\""+id+"\"}";
			                	   		$.ajax({
			                	   	      	  type:"post",
			                	   	          contentType:"application/json; charset=UTF-8",
			                	   	          url: ctx + "/projectAttachment/delete/"+id,
			                	   	          dataType:"json",
			                	   	          success: function(msg){
			                	   	        	  if(msg.code == 0){
			                	   	        		bootbox.alert("删除尽调文件失败了.");
			                	   	        	  }
			                	   	        	  oTable1.fnClearTable();
			                	   	          },
			                	   	          error: function (msg) {
			                	   	          	bootbox.alert(msg.message);
			                	   	          }
			                	   	      });
			                	   	 }
			                	   	 $(this).closeDialog(modal); 
			                	    }
			                	});
			                    return;
			                }));
			                //重命名尽调文件
			                $('#modelEditable_report').on("click", "a.modify", (function (e) {
			                    e.preventDefault();
			                    var nRow = $(this).parents('tr')[0];
			                    var id = nRow.children[0].id;
			                    var name = nRow.children[0].name;
			                    $("#project_attachment_id").val(id);
			                    $("#old_file_name").html(name);
			                    $("#report_rename").click();
			                    $("#modify_file_name").val("");
			                    return;
			                }));
			}
		};

	}();

	return {
		init : function() {
			editable1.init();
		}
	};
}();

var ProjectGroup = function() {
	var editable2 = function() {

		return {
			init : function() {
				oTable2 = $('#group_options_table').dataTable(
								{
									"autoWidth" : false,
									"lengthMenu" : [ [ 10, 15, 20, 50, -1 ],
											[ 10, 15, 20, 50, "All" ] ],
									"displayLength" : -1,
									"language" : {
										"lengthMenu" : "每页 _MENU_ 条记录",
										"paginate" : {
											"previous" : "上一页",
											"next" : "下一页"
										},
										"info" : "",// "从 _START_ 到 _END_ 条，总记录为
													// _TOTAL_ 条",
										"infoEmpty" : "",// 记录数为0",
										"sZeroRecords" : "找不到相关数据"
									},
									"bPaginate" : false, // 是否显示分页
									"bLengthChange" : false, // 每页显示的记录数
									"columnDefs" : [ {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 0 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 1 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 2 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 3 ]
									} ],
									"columns" : [ {
										"data" : "empEmp"
									}, {
										"data" : "empMobile"
									}, {
										"data" : "isPrincipal"
									}, {
										"data" : "operater"
									}],
									"filter" : false,
									"processing" : false,
									"serverSide" : true,
									"ajaxSource" : ctx
											+ "/approveRoleGroup/querySurveyRole",
									"serverMethod" : "post",
									"fnRowCallback" : function(nRow, aData,displayIndex) {
										nRow.children[0].id = aData.approveRoleGroupId;
										nRow.children[0].name = aData.contractName;
										nRow.children[0].employeeId = aData.employeeId;
										$('td:eq(0)', nRow).html(aData.empName);
				                	    $('td:eq(1)', nRow).html(aData.empMobile);
				                	    if(aData.isPrincipal){
				                		   $('td:eq(2)', nRow).html('是');
				                		   $('td:eq(3)', nRow).html('</a>&nbsp;&nbsp;&nbsp;<a class="cancel fa fa-user-times fa-lg" title="取消负责人" href="javascript:;"></a>');
				                	    }else{
				                		   $('td:eq(2)', nRow).html('否');
				                		   $('td:eq(3)', nRow).html('<a class="delete fa fa-times-circle-o fa-lg" title="移除" href="javascript:;"></a>&nbsp;&nbsp;&nbsp;<a class="principal fa fa-child fa-lg" title="设为负责人" href="javascript:;"></a>');
				                	    }
				                       return nRow;
									},
									"fnServerData" : function(ajaxSource,dataSet, fnCallback) {
						                   var json = "{";
						                   var s;
						                   for (var i = 0; i < dataSet.length; i++) {
						                       s = dataSet[i];
						                   	   if (s.name == 'sEcho') {
						                   		   json = json + '"echo":' + s.value;
							                   } else if (s.name == 'iDisplayStart') {
							                	   json = json + ',"start":' + s.value;
							                   } else if (s.name == 'iDisplayLength') {
							                	   json = json + ',"pageSize":' + s.value;
							                   }
						                   }
						                   var id=$("#group_project_eventId").val();
						                   json=json+",\"id\":\""+id+"\"}";
					                       $.ajax({
					                       	"contentType":"application/json; charset=UTF-8",
					                           "dataType" : 'json',
					                           "type" : "POST",
					                           "url" : ajaxSource,
					                           "data" : json,
					                           "success" : fnCallback
					                       });
					                   },
								});
				 // 移除成员
                $('#group_options_table').on("click", "a.delete", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var groupId = nRow.children[0].id;
                    var employeeId = nRow.children[0].employeeId;
                    $.teninedialog({
                        title:'系统提示',
                        content:'确认移除该成员吗?',
                        showCloseButton:false,
                        otherButtons:["确定","取消"],
                        otherButtonStyles:['btn-primary','btn-white'],
                        bootstrapModalOption:{keyboard: true},
                        clickButton:function(sender,modal,index){
                       	 if(index == 0){
	                          json="{\"groupId\":\""+groupId+"\",\"employeeId\":\""+employeeId+"\",\"type\":\""+1+"\"}";
	                          RolesSetting(json);
                       	 }
                       	 	  $(this).closeDialog(modal); 
                        }
                    });
                    return;
                }));
                // 设为负责人
                $('#group_options_table').on("click", "a.principal", (function (e) {
                	 e.preventDefault();
                	  var nRow = $(this).parents('tr')[0];
                      var groupId = nRow.children[0].id;
                      var employeeId = nRow.children[0].employeeId;
                     $.teninedialog({
                         title:'系统提示',
                         content:'确认设置该成员为负责人吗?',
                         showCloseButton:false,
                         otherButtons:["确定","取消"],
                         otherButtonStyles:['btn-primary','btn-white'],
                         bootstrapModalOption:{keyboard: true},
                         clickButton:function(sender,modal,index){
                        	 if(index == 0){
                                  json="{\"groupId\":\""+groupId+"\",\"employeeId\":\""+employeeId+"\",\"type\":\""+2+"\"}";
                                  RolesSetting(json);
                        	 }
                        	 	  $(this).closeDialog(modal); 
                         }
                     });
                     return;
                }));
                // 取消负责人
                $('#group_options_table').on("click", "a.cancel", (function (e) {
                	 e.preventDefault();
                	 var nRow = $(this).parents('tr')[0];
                     var groupId = nRow.children[0].id;
                     var employeeId = nRow.children[0].employeeId;
                     $.teninedialog({
                         title:'系统提示',
                         content:'确认移除该负责人吗?',
                         showCloseButton:false,
                         otherButtons:["确定","取消"],
                         otherButtonStyles:['btn-primary','btn-white'],
                         bootstrapModalOption:{keyboard: true},
                         clickButton:function(sender,modal,index){
                        	 if(index == 0){
                                  json="{\"groupId\":\""+groupId+"\",\"employeeId\":\""+employeeId+"\",\"type\":\""+3+"\"}";
                                  RolesSetting(json);
                        	 }
                        	 	  $(this).closeDialog(modal); 
                         }
                     });
                     return;
                }));				
			}
		};
	}();

	return {
		init : function() {
			editable2.init();
		}
	};
}();


$("#btn_rename_project_attachment").click(function(){
	var file_name = $('#modify_file_name').val();
	var size = file_name.length;
	var old_name = $('#old_file_name').html();
	var id = $('#project_attachment_id').val();
	if(size >10 || size <=0){
		bootbox.alert("文件名长度长度需在1到10个字符之间");
		return;
	}
	if(file_name == old_name){
		bootbox.alert("新名称与旧名称相同");
		return;
	}
	json = "{\"id\":\""+id+"\",\"contractName\":\""+file_name+"\"}";
    var str = json;
    $.ajax({
    	type:"post",
        contentType:"application/json; charset=UTF-8",
        url: ctx + "/projectAttachment/rename",
        data:json,
        dataType:"json",
        success: function(msg){
        	$('#dsimiss_rename_attachment').click();
        	oTable1.fnClearTable();
        },
        error: function (msg) {
        	bootbox.alert(msg.message);
        }
    });
});
//投资部门主管审批录入项目
$("#btn_approve_project_new").click(function() {
	var suggest = $("#approve_project_suggestion").val();
	if (suggest == "") {
		 $("#approve_project_err_span").css('display','block');
		return;
	}
	var form = $("form#approve_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+2+",\"state\":"+3+",\"isSugesst\":"+true+",\"flag\":"+true+",\"isMeeting\":"+false+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//法律合规部立项风控审核
$("#btn_windControl_project_new").click(function() {
	var suggest = $("#windControl_project_suggestion").val();
	if (suggest == "") {
		 $("#windControl_err_span").css('display','block');
		return;
	}
	var form = $("form#windControl_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+3+",\"state\":"+4+",\"isSugesst\":"+true+",\"flag\":"+true+",\"isMeeting\":"+false+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//尽调小组负责人确认尽调完成
$("#btn_carefulComplete_project_new").click(function() {
	var suggest = $("#carefulComplete_project_suggestion").val();
	if (suggest == "") {
		 $("#carefulComplete_err_span").css('display','block');
		return;
	}
	var form = $("form#carefulComplete_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+4+",\"state\":"+5+",\"isSugesst\":"+true+",\"flag\":"+true+",\"isMeeting\":"+false+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//初审委员会个人表决
$("#btn_vote_project_new").click(function() {
	var suggest = $("#vote_project_suggestion").val();
	if (suggest == "") {
		 $("#vote_err_span").css('display','block');
		return;
	}
	var form = $("form#vote_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+5+",\"state\":"+6+",\"isSugesst\":"+true+",\"flag\":"+false+",\"isMeeting\":"+false+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//初审委员会负责人提交初审结果
$("#btn_firstTrial_project_new").click(function() {
	var suggest = $("#firstTrial_project_suggestion").val();
	if (suggest == "") {
		 $("#firstTrial_err_span").css('display','block');
		return;
	}
	var form = $("form#firstTrial_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+5+",\"state\":"+6+",\"isSugesst\":"+true+",\"flag\":"+true+",\"isMeeting\":"+true+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//复审委员会个人决议
$("#btn_decision_project_new").click(function() {
	var suggest = $("#decision_project_suggestion").val();
	if (suggest == "") {
		 $("#decision_err_span").css('display','block');
		return;
	}
	var form = $("form#decision_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+7+",\"state\":"+8+",\"isSugesst\":"+true+",\"flag\":"+false+",\"isMeeting\":"+false+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//复审委员会负责人提交复审结果
$("#btn_reexamine_project_new").click(function() {
	var suggest = $("#reexamine_project_suggestion").val();
	if (suggest == "") {
		 $("#reexamine_err_span").css('display','block');
		return;
	}
	var form = $("form#reexamine_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+7+",\"state\":"+8+",\"isSugesst\":"+true+",\"flag\":"+true+",\"isMeeting\":"+true+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//最终审批
$("#btn_lastInstance_project_new").click(function() {
	var suggest = $("#lastInstance_project_suggestion").val();
	if (suggest == "") {
		 $("#lastInstance_err_span").css('display','block');
		return;
	}
	var form = $("form#lastInstance_project_form").serializeJSON();
	var js = form.replace('}', ',');
	json = "\"step\":"+9+",\"state\":"+10+",\"isSugesst\":"+true+",\"flag\":"+true+",\"isMeeting\":"+true+"";
 	json = js + json + "}";
 	FlowUnitiveHandleRequest(json);
});

//上传尽调文件
function uploadReportFile(){
	if(!$("#relatedFile").val()){
		bootbox.alert("请先添加文件！");
		return;
	}
	 $.ajaxFileUpload({
            url: ctx + '/projectAttachment/uploadRelatedFile',
            type: 'post',
            secureuri: false,
            fileElementId: 'relatedFile',
            dataType: 'json',
            data:{'projectId': $("#report_project_eventId").val(),'type':2},
            success: function(data, status){
            	if (data.code == 1) {
            		bootbox.dialog({
    					message : "上传成功！ ",
    					title : "温馨提示：",
    					buttons : {
    						main : {
    							label : "确定",
    							className : "btn btn-outline btn-primary",
    							callback : function() {
    								oTable1.fnClearTable();
    							}
    						}
    					}
    				});
            		
            	} else {
            		bootbox.alert(data.message);
            	}
            },
            error: function(msg, status, e){
            	bootbox.alert("上传失败！");
            }
        });
} 

//流程处理公共的ajax请求方法
function FlowUnitiveHandleRequest(json){
	  $.ajax({
      	type:"post",
          contentType:"application/json; charset=UTF-8",
          url: ctx + "/projectFlow/proFlowUnitiveHandle",
          data:json,
          dataType:"json",
          success: function(msg){
          	$.teninedialog({
                  title:'系统提示',
                  content:msg.message,
                  showCloseButton:false,
                  otherButtons:["确定"],
                  otherButtonStyles:['btn-primary'],
                  bootstrapModalOption:{keyboard: true},
                  clickButton:function(sender,modal,index){
                  	location.reload();
                  }
              });
          },
          error: function (msg) {
          	bootbox.alert(msg.message);
          }
      });
}

//为项目成立尽调小组
function createSurveyGroup(json){
	  $.ajax({
      	type:"post",
          contentType:"application/json; charset=UTF-8",
          url: ctx + "/approveRoleGroup/createSurveyGroup",
          data:json,
          dataType:"json",
          success: function(msg){
          },
          error: function (msg) {
          }
      });
}

function RolesSetting(json){
	$.ajax({
    	type:"post",
        contentType:"application/json; charset=UTF-8",
        url: ctx + "/approveRoleGroup/roleSet",
        data:json,
        dataType:"json",
        success: function(msg){
        	$.teninedialog({
                title:'系统提示',
                content:msg.message,
                showCloseButton:false,
                otherButtons:["确定"],
                otherButtonStyles:['btn-primary'],
                bootstrapModalOption:{keyboard: true},
                clickButton:function(sender,modal,index){
                	$(this).closeDialog(modal); 
                	oTable2.fnClearTable();
                }
            });
        },
        error: function (msg) {
        	bootbox.alert("服务器偷了个小懒,分配理财师失败了!");
        }
    });
}

//获取尽调小组审批团队
function getSurveyGroup(json){
	$.ajax({
    	type:"post",
        contentType:"application/json; charset=UTF-8",
        url: ctx + "/approveRoleGroup/querySurveyRole",
        data:json,
        dataType:"json",
        success: function(msg){
        	$('#approve_group_project_id').val(msg.groupId);
        },
        error: function (msg) {
        }
    });
}

//Autocomplete
$("#tags").autocomplete({
    source: function(query,process){
        $.post(ctx + "/investor/employee/"+query.term,{"matchCount":200},function(data){
        	var ebean = []
        	for (var int = 0; int < data.length; int++) {
        		var temp = [];
        		temp.label = data[int].employeeName +"  "+ data[int].employeeNo;
        		temp.value = data[int].employeeNo;
        		temp.id = data[int].employeeId;
        		temp.name = data[int].employeeName;
        		ebean.push(temp);
    		}
            return process(ebean);
        });
    },
    search:function(event, ui){
    	$("#employeeName").html('');
        $("#employeeNo").html('');
        $("#employeeId").val('');
    },
    select: function(event, ui) {
        $("#tags").val(ui.item.label);
        $("#employeeName").html(ui.item.name);
        $("#employeeNo").html(ui.item.value);
        $("#employeeId").val(ui.item.id);
        var uistr =ui.item;
        // 阻止事件的默认行为
        event.preventDefault(); 
    }
});

$('#btn_deal_emp_new').click(function(){
	var employeeId = $('#employeeId').val();
	var employeeName = $('#employeeName').html();
	var groupId = $('#approve_group_project_id').val();
	if (employeeId == null || employeeId == '') {
		bootbox.alert("请选择理财师！");
		return;
	}
	json = "{\"employeeId\":\""+employeeId+"\",\"groupId\":\""+groupId+"\"}";
	$.ajax({
    	type:"post",
        contentType:"application/json; charset=UTF-8",
        url: ctx + "/approveRoleGroup/allotEmp",
        data:json,
        dataType:"json",
        success: function(msg){
        	$.teninedialog({
                title:'系统提示',
                content:msg.message,
                showCloseButton:false,
                otherButtons:["确定"],
                otherButtonStyles:['btn-primary'],
                bootstrapModalOption:{keyboard: true},
                clickButton:function(sender,modal,index){
                	$(this).closeDialog(modal);
                	oTable2.fnClearTable();
                	$("#employeeName").html('');
                    $("#employeeNo").html('');
                    $("#employeeId").val('');
                    $("#tags").val("");
                }
            });
        },
        error: function (msg) {
        	bootbox.alert("服务器偷了个小懒,分配理财师失败了!");
        }
    });
});

//去除换行、空格
function clearBr(key)
{
	key = key.replace(/\s+/g, "");	
    key = key.replace(/<\/?.+?>/g,"");
    key = key.replace(/[\r\n]/g, "");
    return key;
}

/** 
 * 将数值四舍五入(保留2位小数)后格式化成金额形式 
 * @param num 数值(Number或者String) 
 * @return 金额格式的字符串
 * @type String 
 */  
function formatCurrency(num) {  
    num = num.toString().replace(/\$|\,/g,'');  
    if(isNaN(num))  
        num = "0";  
    sign = (num == (num = Math.abs(num)));  
    num = Math.floor(num*100+0.50000000001);  
    cents = num%100;  
    num = Math.floor(num/100).toString();  
    if(cents<10)  
    cents = "0" + cents;  
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)  
    num = num.substring(0,num.length-(4*i+3))+','+  
    num.substring(num.length-(4*i+3));  
    return (((sign)?'':'-') + num + '.' + cents);  
}  